/**
 * DiggApiNet - Digg API .NET Wrapper
 * 
 * Author: Sean Hickey
 * Link: http://www.headzoo.com/digg_api_net
 * License: GPL v2 ( http://www.gnu.org/licenses/gpl.txt )
 */
using System;
using System.Text;
using System.Xml;
using System.Collections;

namespace DiggApiNet
{
    public class DiggReturnBaseCollection : DiggApi
    {
        #region Private Vars
        private DateTime    _timestamp;
        private DateTime    _min_date;
        private long        _total;
        private int         _offset;
        private int         _count;
        #endregion

        #region Public Vars
        public DateTime     Timestamp
        {
            get
            {
                return _timestamp;
            }
            set
            {
                _timestamp = value;
            }
        }
        public DateTime     MinDate
        {
            get
            {
                return _min_date;
            }
            set
            {
                _min_date = value;
            }
        }
        public long         Total
        {
            get
            {
                return _total;
            }
            set
            {
                _total = value;
            }
        }
        public int          Offset
        {
            get
            {
                return _offset;
            }
            set
            {
                _offset = value;
            }
        }
        public int          Count
        {
            get
            {
                return _count;
            }
            set
            {
                _count = value;
            }
        }
        #endregion

        public DiggReturnBaseCollection() { }
        public DiggReturnBaseCollection(XmlDocument xml_doc, string top_node_name)
        {
            if (xml_doc.SelectSingleNode(top_node_name) == null) {
                throw new DiggApiException("XML response appears to be malformed, or contains unexpected data.");
            }

            XmlNode node = xml_doc.SelectSingleNode(top_node_name);
            if (node.Attributes["timestamp"] != null) {
                _timestamp = GetDateTimeFromTimeStamp(node.Attributes["timestamp"].InnerText);
            }
            if (node.Attributes["min_date"] != null) {
                _min_date = GetDateTimeFromTimeStamp(node.Attributes["min_date"].InnerText);
            }
            if (node.Attributes["total"] != null) {
                _total = long.Parse(node.Attributes["total"].InnerText);
            }
            if (node.Attributes["offset"] != null) {
                _offset = int.Parse(node.Attributes["offset"].InnerText);
            }
            if (node.Attributes["count"] != null) {
                _count = int.Parse(node.Attributes["count"].InnerText);
            }
        }
    }
}
